
const TerserPlugin = require('terser-webpack-plugin')
const CracoLessPlugin = require('craco-less');
const { $ } = require('./pathConfig')
const proxyBuilder = require('./proxy')

module.exports = {
  webpack: {
    alias: {
      '@src': $("./src"),
      '@apis': $('./src/apis'),
      '@assets': $('./src/assets'),
      '@styles': $('./src/assets/styles'),
      '@images': $('./src/assets/images'),
      '@components': $('./src/components'),
      '@contexts': $('./src/contexts'),
      '@routes': $('./src/routes'),
      '@views': $('./src/views'),
      '@vendors': $('./src/vendors'),
      '@core': $('./src/vendors/fc-core'),
      '@network': $('./src/vendors/fc-network'),
      '@fcRouter': $('./src/vendors/fc-router'),
      '@utils': $('./src/utils'),
      '@commonMethod': $('./src/utils/commonMethod'),
      '@rules': $('./src/utils/rules')
    },
    configure: (webpackConfig, { env, paths }) => {
      const isPro = env === 'production'
      webpackConfig.optimization.minimizer = [
        new TerserPlugin({
          terserOptions: {
            output: {
              comments: false,
            },
            compress: {
              drop_console: isPro, // 生产环境下移除控制台所有的内容
              drop_debugger: false, // 移除断点
              pure_funcs: isPro ? ["console.log"] : "", // 生产环境下移除console
            },
          },
          extractComments: false,
        }),
      ]
      webpackConfig.externals= {
        'BMapGL':'BMapGL'
      }
      webpackConfig.output.path = $('./riskmapweb_9197') // 修改打包生成的文件夹路径
      paths.appBuild = 'riskmapweb_9197' //修改打包生成的文件夹名称
      return webpackConfig
    }
  },
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            // modifyVars: { '@primary-color': '#e33f31' },
            javascriptEnabled: true,
          },
        },
      },
    },
  ],
  devServer: {
    port: 9197,
    proxy: proxyBuilder(),
    // proxy: {
    //   '/postman/': {
    //     target: 'https://postman-echo.com',
    //     pathRewrite: {'^/postman/': ''},
    //     secure: false,
    //     changeOrigin: true,
    //   }
    // },
  },
}